<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <script src="../jquery-3.1.1.js"></script>
    <title>jq轮播图</title>
    <style>
        ul,li{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        #box{
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
            cursor: pointer;
            z-index: 999;
        }
        #box .list li{
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        #box .list li.current{
            display: block;
        }
        #box .count{
            position: absolute;
            right: 10px;
            bottom: 10px;
        }
        #box .count li{
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #fa0;
            text-align: center;
            line-height: 20px;
            margin-left: 10px;
            color: #fff;
            opacity: 0.8;
            cursor: pointer;
        }
        #box .count li.current{
            background-color: #f60;
            opacity: 1;
        }
        .left,.right{
            width: 40px;
            height: 40px;
            background-color: black;
            opacity: .4;
            text-align: center;
            line-height: 40px;
            color: white;
            position: absolute;
            display: none;
            z-index: 9999;
        }
        .left{
            top: 120px;
            left: 20px;
        }
        .right{
            top: 120px;
            right: 20px;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul class="list"> 
            <li class="current"><img src="../img/01.jpg" alt=""></li>
            <li><img src="../img/02.jpg" alt=""></li>
            <li><img src="../img/03.jpg" alt=""></li>
            <li><img src="../img/04.jpg" alt=""></li>
            <li><img src="../img/05.jpg" alt=""></li>
        </ul>
        <ul class="count">
            <li class="current">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <div class="left"><</div>
        <div class="right">></div>
    </div>
    
</body>
</html>
<script>
    
    var current = 0;
    var timer = null;
    timer = setInterval(autoPlay,2000);

    //自动播放
    function autoPlay(){
        current++;
        if(current >= $('.list img').length){
            current = 0;
        } 
        show(current);
    }
    function show(index){
        current = index;
        $('.list li').eq(current).addClass('current').siblings().removeClass('current');
        $('.count li').eq(current).addClass('current').siblings().removeClass('current'); 
    }
    //鼠标经过数字 点击 
    $('.count li').mouseover(function(){
            clearInterval(timer);
            show($(this).index());
            
    });
    $('.count li').mouseleave(function(){
            timer = setInterval(autoPlay,2000);
    });

    //鼠标进入img 停止计时 显示 向前 向后按钮 触发点击事件
    $('#box').hover(function(){
        $('.left,.right').css('display','block');
        $('.left').click(function(){
            if(current < 1){
                current  = 5;
            }
            show(current-1);
            clearInterval(timer);
        });

        $('.right').click(function(){
            if(current > 3){
                current = -1;
            }
            show(current+1);
            clearInterval(timer);
        });
    },function(){
        $('#box').find('.left,.right').hide();
    });   
</script>